package com.cg.bank.web.util;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter;

public class URLFilter extends UrlRewriteFilter {
	private String character;

	@Override
	public void init(FilterConfig config) throws ServletException {
		// 载入配置编码
		String character = config.getInitParameter("character");
		if (character == null) {
			this.character = "UTF-8";
		} else {
			this.character = character;
		}
		super.init(config);
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		// 设置请求编码
		req.setCharacterEncoding(character);
		super.doFilter(req, resp, chain);
	}

}